package ch.zhaw.cctd.domain.prototype;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * Representiert ein MapTyp und dessen Einstellungen im XML Config File
 * @author Rolf Koch
 * @author Benjamin Felder
 */
public class MapPrototype extends Prototype implements Serializable {

	private static final long serialVersionUID = 884848667613182833L;

	public MapPrototype(Map<String, String> data) {
		super(data);
		final String[] spawnpointKeys = new String[] {
			"id", "x", "y", "next.waypoint.refid", "player.refid"
		};
		this.spawnpointprototypes = this.getDataList("points.spawnpoints.spawn", 
				new Prototype.DataMapCallback<SpawnPointPrototype>(spawnpointKeys) {
			@Override
			public SpawnPointPrototype mapCall(Map<String,String> data) {
				return new SpawnPointPrototype(data);
			}
		}, spawnpointKeys);
		final String[] waypointKeys = new String[] {
				"id", "x", "y", "next.waypoint.refid"
		};
		this.waypointprototypes = this.getDataList("points.waypoints.waypoint", 
				new Prototype.DataMapCallback<WayPointPrototype>(waypointKeys) {
			@Override
			public WayPointPrototype mapCall(Map<String,String> data) {
				return new WayPointPrototype(data);
			}
		}, waypointKeys);
		this.mapelementprototypes = MapElementPrototype.generateMapElementPrototypes(data);
		final String[] maptextureKeys = new String[] {"id", "texture"};
		this.maptextureprototypes = this.getDataList("textures.texture", 
				new Prototype.DataMapCallback<MapTexturePrototype>(maptextureKeys) {
			@Override
			public MapTexturePrototype mapCall(Map<String, String> data) {
				return new MapTexturePrototype(data);
			}
		}, maptextureKeys);
	}
	
	private final List<SpawnPointPrototype> spawnpointprototypes;
	private final List<WayPointPrototype> waypointprototypes;
	private final List<MapElementPrototype> mapelementprototypes;
	private final List<MapTexturePrototype> maptextureprototypes;
	
	public String getName() {
		return this.getValue("meta.name.#text");
	}
	
	public int getSize() {
		return this.getIntegerValue("meta.size.#text");
	}
	
	public int getInitialResources() {
		return this.getIntegerValueWith0("meta.init-resources.#text");
	}

	public List<SpawnPointPrototype> getSpawnPointPrototypes() {
		return this.spawnpointprototypes;
	}

	public List<WayPointPrototype> getWayPointsPrototypes() {
		return this.waypointprototypes;
	}
	
	public List<MapElementPrototype> getMapElementPrototypes() {
		return this.mapelementprototypes;
	}
	
	public List<MapTexturePrototype> getMapTexturePrototypes() {
		return this.maptextureprototypes;
	}

	public int getMaxCreep() {
		return this.getIntegerValueWith0("meta.maxcreep.#text");
	}

}
